﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using FrienDev.BusinessRules;
using FrienDev.Data;
using System.Collections.Generic;

public partial class Controls_Activity_ImageList : System.Web.UI.UserControl
{
    private int m_activityId;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["activityid"]))
        {
            m_activityId = Convert.ToInt32(Request.QueryString["activityid"]);
            hl_MorePhotos.NavigateUrl = "~/Activity/ImageListDetail.aspx?activityid=" + m_activityId;
            dl_ActivityImage.ItemDataBound += new DataListItemEventHandler(dl_ActivityImage_ItemDataBound);
            InitDL_ActivityImage();
        }
    }

    void dl_ActivityImage_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        Image img = (Image)e.Item.FindControl("img_ActivityImage");
        img.ImageUrl = PhotoRules.Instance.GetActivitySmallPhotoUrl(m_activityId, img.ImageUrl);
        Label lbImageID=(Label)e.Item.FindControl("lb_ImageID");
        HyperLink hlActivityImage = (HyperLink)e.Item.FindControl("hl_ActivityImage");
        hlActivityImage.NavigateUrl = "~/Activity/ImageDetail.aspx?activityid="+m_activityId+"&imageid=" + lbImageID.Text;
        HyperLink hlActivityImageDescription = (HyperLink)e.Item.FindControl("hl_ActivityImageDescription");
        hlActivityImageDescription.NavigateUrl = "~/Activity/ImageDetail.aspx?activityid=" + m_activityId + "&imageid=" + lbImageID.Text;
        if (hlActivityImageDescription.Text.Trim() == "")
        {
            hlActivityImageDescription.Visible = false;
        }
        else
        {
            hlActivityImageDescription.ToolTip = hlActivityImageDescription.Text;
            hlActivityImageDescription.Text = HtmlHelper.InterceptSubString(hlActivityImageDescription.Text, 16, false);
        }
       
    }

    private void InitDL_ActivityImage()
    {
        IEnumerable<Photo> photos = PhotoRules.Instance.GetActivityPhotosFor10(m_activityId);
        if (photos.Count() == 0)
        {
            pn_NoPhotoTip.Visible = true;
        }
        else
        {
            dl_ActivityImage.DataSource = photos;
            dl_ActivityImage.DataBind();
        }
    }
}
